/* Ejercicio 3.49
   ejer3_49.c */
#include <stdio.h>

/* funcion main, el programa inicia aca */
int main( void )
{
    int number, encrypted, a, aux, digit;
    int p1, p2;

    printf( "Enter a 4 digits number: " );
    scanf( "%d", &number );
    a = number;
    encrypted = 0;
    aux = 1;

    while ( a != 0 ) {
        encrypted = encrypted + aux * ( ( a % 10 + 7 ) % 10 );
        aux *= 10;
        a /= 10;
    }
    p1 = encrypted / 100;
    p2 = encrypted % 100;
    encrypted = p2 * 100 + p1;
    printf ("%d encrypted is %d\n\n", number, encrypted );

    printf( "Enter a encrypted number: " );
    scanf( "%d", &encrypted );
    p1 = encrypted / 100;
    p2 = encrypted % 100;
    a = p2 * 100 + p1;
    number = 0;
    aux = 1;

    while ( a != 0 ) {
        digit = a % 10;
        number = number + aux * ( ( digit ) >= 7 ? digit - 7 : digit + 3 );
        aux *= 10;
        a /= 10;
    }

    printf( "%d decrypted is: %d\n", encrypted, number );

	return 0;
} /* fin de la funcion main */
